package hsintiao.com.xintiaoAPP.controller;


import hsintiao.com.xintiaoAPP.annotation.PassToken;
import hsintiao.com.xintiaoAPP.entity.Feedback;
import hsintiao.com.xintiaoAPP.entity.HelpFeedback;
import hsintiao.com.xintiaoAPP.entity.single.SingleLong;
import hsintiao.com.xintiaoAPP.entity.single.SingleString;
import hsintiao.com.xintiaoAPP.service.HelpService;
import hsintiao.com.xintiaoAPP.util.AjaxResult;
import hsintiao.com.xintiaoAPP.util.ResponseCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//帮助与反馈页面
@RestController
@RequestMapping("/help")
public class HelpController {
    @Autowired
    private HelpService helpService;

    //获取帮助反馈页面的基本帮助
    @PostMapping("/getTopHelp")
    @ResponseBody
    public AjaxResult getTopHelp(){
        try {
            AjaxResult result = helpService.getTopHelp();
            return result;
        }catch (Exception e){
            return AjaxResult.me().setSuccess(false).setCode(ResponseCode.FAILURE.getCode())
                    .setMessage("获取信息失败，请重试");
        }
    }

    //获取所有帮助信息
    @PostMapping("/getAllHelp")
    @ResponseBody
    public AjaxResult getAllHelp(){
        try {
            AjaxResult allHelp = helpService.getAllHelp();
            return allHelp;
        }catch (Exception e){
            return AjaxResult.me().setSuccess(false).setCode(ResponseCode.FAILURE.getCode())
                    .setMessage("获取信息失败，请重试");
        }
    }


    //获取单个帮助信息
    @PostMapping("/getDetailedHelp")
    @ResponseBody
    public AjaxResult getDetailedHelp(@RequestBody SingleLong id){
        try {
            AjaxResult detailedHelp = helpService.getDetailedHelp(id.getId());
            return detailedHelp;
        }catch (Exception e){
            return AjaxResult.me().setSuccess(false).setCode(ResponseCode.FAILURE.getCode())
                    .setMessage("获取信息失败，请重试");
        }
    }

    //反馈
    @PostMapping("/feedback")
    @ResponseBody
    public AjaxResult feedback(@RequestBody Feedback feedback){
        try {
            if(feedback != null && !feedback.getContent().equals("")){
                AjaxResult saveFeedback = helpService.saveFeedback(feedback);
                return saveFeedback;
            }else {
                return AjaxResult.me().setSuccess(false).setCode(ResponseCode.FAILURE.getCode())
                        .setMessage("反馈失败，请重试");
            }
        }catch (Exception e){
            return AjaxResult.me().setSuccess(false).setCode(ResponseCode.FAILURE.getCode())
                    .setMessage("反馈失败，请重试");
        }

    }


}
